home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performBoolean.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  9.2 KB  |  374 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Sept 30, 1998
  22. //  Author:         rs
  23. //
  24. //  Description:
  25. //      This script defines the option box for the boolean surface menu item.
  26. //
  27. //  Input Arguments:
  28. //      int action
  29. //        1 - just execute the boolean operation
  30. //        2 - return the script that would do it
  31. //
  32. //  Return Value:
  33. //      None.
  34. //
  35.  
  36. proc setOptionVars(
  37.     int $opType,
  38.     int $forceFactorySettings)
  39. {
  40.  
  41.     switch( $opType ) {
  42.         case 0 :
  43.             if( $forceFactorySettings || 
  44.                 !`optionVar -exists nurbsUnionDeleteInput` ) {
  45.                 optionVar -intValue nurbsUnionDeleteInput 1 ;
  46.             }
  47.             break ;
  48.  
  49.         case 1 :
  50.             if( $forceFactorySettings || 
  51.                 !`optionVar -exists nurbsSubtractDeleteInput` ) {
  52.                 optionVar -intValue nurbsSubtractDeleteInput 1 ;
  53.             }
  54.             break ;
  55.  
  56.         case 2 :
  57.             if( $forceFactorySettings || 
  58.                 !`optionVar -exists nurbsIntersecttDeleteInput` ) {
  59.                 optionVar -intValue nurbsIntersectDeleteInput 1 ;
  60.             }
  61.             break ;
  62.     }
  63. }
  64. proc string assembleCmd( int $ni, int $op )
  65. //
  66. //    Description :
  67. //        To assemble boolean cmd.
  68. //
  69. {
  70.  
  71.     setOptionVars( $op, false ) ;
  72.  
  73.     int $history = `constructionHistory -q -tgl`;
  74.     int $delInputs = 0;
  75.     switch($op) {
  76.         case 0 :
  77.         $delInputs = `optionVar -q nurbsUnionDeleteInput`;
  78.         break ;
  79.         case 1 :
  80.         $delInputs = `optionVar -q nurbsSubtractDeleteInput` ;
  81.         break ;
  82.         case 2 :
  83.         $delInputs = `optionVar -q nurbsIntersectDeleteInput` ;
  84.         break ;
  85.     }
  86.     string $cmd = "nurbsBooleanPreset 1 {";
  87.     $cmd = $cmd + "\"" + $history + "\", ";
  88.     $cmd = $cmd + "\"" + $ni + "\", ";
  89.     $cmd = $cmd + "\"" + $op + "\", ";
  90.     $cmd = $cmd + "\"" + $delInputs + "\" }";
  91.     return $cmd;
  92. }
  93.  
  94. proc string booleanHelp()
  95. {
  96.     string $cmdHelp = "Command:<nurbsBoolean>- perform union or subtract or intersect \n";
  97.     string $selectHelp = ("Selection: One or more NURBS surfaces followed " +
  98.                           "by a second set of NURBS surface.");
  99.     return $cmdHelp+$selectHelp;
  100. }
  101.  
  102. global proc nurbsBooleanCallback( 
  103.     string $parent,
  104.     int $doIt,
  105.     int $whichOp,
  106.     string $goToTool )
  107. {
  108.     setParent $parent;
  109.     string $label;
  110.  
  111.     // get Values from controls.
  112.     //
  113.     int $di = `checkBoxGrp -q -v1 nurbsBooleanDeleteInputWidget`;
  114.  
  115.     switch( $whichOp ) {
  116.         case 0 :
  117.             optionVar -intValue nurbsUnionDeleteInput $di;
  118.             $label = "Union";
  119.             break ;
  120.         case 1 :
  121.             optionVar -intValue nurbsSubtractDeleteInput $di;
  122.             $label = "Subtract";
  123.             break ;
  124.         case 2 :
  125.             optionVar -intValue nurbsIntersectDeleteInput $di;
  126.             $label = "Intersect";
  127.             break ;
  128.     }
  129.  
  130.     if( 1 == $doIt ) {
  131.         string $list[] ; 
  132.         performBoolean( 0, $whichOp, $list , $goToTool ); 
  133.         string $tmpCmd = "performBoolean( 0, " + $whichOp + ", ";
  134.         $tmpCmd += "{ \"\"}, \"" + $goToTool + "\")";
  135.         addToRecentCommandQueue $tmpCmd $label;
  136.     }
  137.     else if( $doIt ) {
  138.         setToolTo $goToTool;
  139.     }
  140. }
  141.  
  142.  
  143. global proc nurbsBooleanSetup(
  144.     string $parent,
  145.     int $forceFactorySettings,
  146.     int $whichOp,
  147.     string $goToTool) 
  148. {
  149.     // retrieve option settings.
  150.     //
  151.     setOptionVars( $whichOp, $forceFactorySettings );
  152.     if( $forceFactorySettings || !`optionVar -ex booleanEuc` ) {
  153.         optionVar -iv ("booleanEuc" + $whichOp) 0;
  154.     }
  155.     if( $forceFactorySettings || !`optionVar -ex booleanLac` ) {
  156.         optionVar -iv ("booleanLac" + $whichOp) 1;
  157.     }
  158.     if( "" != $goToTool ) {
  159.         scriptCtx -e -euc `optionVar -q ("booleanEuc"+$whichOp)` $goToTool;
  160.         scriptCtx -e -lac `optionVar -q ("booleanLac"+$whichOp)` $goToTool;
  161.     }
  162.  
  163.     setParent $parent;
  164.  
  165.     // query the option vars.
  166.     //
  167.     int $di ;
  168.     switch( $whichOp ) {
  169.         case 0 :
  170.             $di = `optionVar -q nurbsUnionDeleteInput`;
  171.             break ;
  172.         case 1 :
  173.             $di = `optionVar -q nurbsSubtractDeleteInput`;
  174.             break ;    
  175.         case 2 :
  176.             $di = `optionVar -q nurbsSubtractDeleteInput`;
  177.             break ;    
  178.     }
  179.     checkBoxGrp -e -v1 $di nurbsBooleanDeleteInputWidget ;
  180.  
  181.     if( "" != $goToTool ) {
  182.         checkBoxGrp -e
  183.           -v1 `scriptCtx -q -exitUponCompletion $goToTool`
  184.           -v2 `scriptCtx -q -enableRootSelection $goToTool`
  185.           scriptToolExtraWidget;
  186.     }
  187. }
  188.  
  189.  
  190. proc nurbsBooleanOptions(
  191.      int $inTheTool,
  192.      int $whichOp,
  193.      string $goToTool )
  194. //
  195. // Desc : 
  196. //        $whichOp = 0 (union ), 1 (subtract)    , 2(intersect).
  197. //
  198. {
  199.     //  Name of the command for this option box.
  200.     //
  201.     string $commandName = "nurbsBoolean";
  202.  
  203.     //  Build the option box actions.
  204.     //
  205.     string $callback = ($commandName + "Callback");
  206.     string $setup = ($commandName + "Setup");
  207.  
  208.     //  Step 1:  Get the option box.
  209.     //  ============================
  210.     string $layout = getOptionBox();
  211.     setParent $layout;
  212.  
  213.     //  Step 2:  Pass the command name to the option box.
  214.     //  =================================================
  215.     setOptionBoxCommandName($commandName);
  216.  
  217.     //  Step 3:  Activate the default UI template.
  218.     //  ==========================================
  219.     setUITemplate -pushTemplate DefaultTemplate;
  220.  
  221.  
  222.     //  Step 4: Create option box contents.
  223.     //  ===================================
  224.  
  225.     //  Turn on the wait cursor.
  226.     //
  227.     waitCursor -state 1;
  228.  
  229.     tabLayout -scr true -tv false;
  230.  
  231.     string $parent = `columnLayout -adjustableColumn 1`;
  232.  
  233.     checkBoxGrp -ncb 1 -l1 "Delete Inputs" nurbsBooleanDeleteInputWidget;
  234.  
  235.     checkBoxGrp -ncb 2 -l "Tool Behavior"
  236.         -l1 "Exit on Completion"
  237.         -v1 on
  238.         -on1 ("scriptCtx -e -euc true " + $goToTool)
  239.         -of1 ("scriptCtx -e -euc false " + $goToTool)
  240.  
  241.         -l2 "Hierarchy Selection"
  242.         -v2 on
  243.         -on2 ("scriptCtx -e -ers true " + $goToTool)
  244.         -of2 ("scriptCtx -e -ers false " + $goToTool)
  245.         scriptToolExtraWidget;
  246.  
  247.     setParent ..;
  248.  
  249.  
  250.     //  Turn off the wait cursor.
  251.     //
  252.     waitCursor -state 0;
  253.  
  254.     //  Step 5: Deactivate the default UI template.
  255.     //  ===========================================
  256.     //
  257.     setUITemplate -popTemplate;
  258.  
  259.  
  260.      //  Step 6: Customize the buttons.
  261.     //  ==============================
  262.  
  263.     //  'Apply' button.
  264.     string $applyBtn = getOptionBoxApplyBtn();
  265.  
  266.     string $opLabel ;
  267.     switch( $whichOp ) {
  268.  
  269.         case 0 : 
  270.             $opLabel = "Union" ;
  271.             break ;
  272.         case 1 : 
  273.             $opLabel = "Subtract" ;
  274.             break ;
  275.         case 2 :
  276.             $opLabel = "Intersect" ;
  277.             break ;
  278.     }
  279.  
  280.     if( $inTheTool ) {
  281.         button -edit -l ($opLabel + " Tool")
  282.             -command ($callback + " " + $parent + " " + 3 + " " + $whichOp +
  283.                 " " + $goToTool )
  284.             $applyBtn;
  285.     } else {
  286.         button -edit -l $opLabel
  287.             -command ($callback + " " + $parent + " " + 1 + " " + $whichOp +
  288.             " \""  + $goToTool + "\"" )
  289.             $applyBtn;
  290.  
  291.     }
  292.  
  293.     //  'Save' button.
  294.     //
  295.     string $saveBtn = getOptionBoxSaveBtn();
  296.     button -edit
  297.         -command ($callback + " " + $parent + " " + 0 + " " + $whichOp +
  298.                   " \"" + $goToTool + "\"; hideOptionBox")
  299.         $saveBtn;
  300.  
  301.     //  'Reset' button.
  302.     //
  303.     string $resetBtn = getOptionBoxResetBtn();
  304.     button -edit
  305.         -command ($setup + " " + $parent + " " + 1 + " " +
  306.                   $whichOp + " \"" + $goToTool + "\"")
  307.         $resetBtn;
  308.     
  309.  
  310.     //  Step 7: Set the option box title.
  311.     //  =================================
  312.     //
  313.     setOptionBoxTitle("NURBS Boolean " + $opLabel +  " Options");
  314.  
  315.     //    Step 8: Customize the 'Help' menu item text.
  316.     //    ============================================
  317.     //
  318.     setOptionBoxHelpTag( "NurbsBoolean" );
  319.  
  320.     //  Step 9: Set the current values of the option box.
  321.     //  =================================================
  322.     //
  323.     eval ($setup + " " + $parent + " " + 0 + " " +
  324.           $whichOp + " \"" + $goToTool + "\"" );
  325.  
  326.     //  Step 10: Show the option box.
  327.     //  =============================
  328.     //
  329.     showOptionBox();
  330. }
  331.  
  332.  
  333. global proc string performBoolean( 
  334.     int $action,
  335.     int $opType,
  336.     string $list1[],
  337.     string $goToTool )
  338. //
  339. //    Description :
  340. //        $action = 0 ==> do the nurbs union|subtract|intersect command.
  341. //      $action = 1 ==>show option box.
  342. //      $action = 2 ==>drag to shelf.
  343. {
  344.     string $cmd = "";
  345.  
  346.     int $inTheTool = false;
  347.     if( 3 == $action ) {
  348.         $action = 1;
  349.         $inTheTool = true;
  350.     }
  351.  
  352.     int $ni = size($list1) ;
  353.  
  354.     // find only valid items.
  355.     //
  356.     switch( $action ) {
  357.         case 0 :
  358.             $cmd = `assembleCmd $ni $opType`;
  359.             eval $cmd;
  360.             break;
  361.  
  362.         case 1 :
  363.             nurbsBooleanOptions( $inTheTool, $opType, $goToTool );
  364.             break ;
  365.  
  366.         case 2 :
  367.             $cmd = `assembleCmd $ni $opType`;
  368.             break;
  369.         default : break;
  370.     }
  371.     return $cmd;
  372. }
  373.  
  374.